<template>
  <div
    :ref="refName"
    :optionData="optionData"
    :title="title"
    style="width: 100%;height: 100%;"
  ></div>
</template>

<script>
import * as echarts from 'echarts'
export default {
  props: {
    refName: {
      type: String,
      default: "ref",
    },
    optionData: {
      type: Object,
    },
    title: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      chartData: null,
    };
  },
  watch: {
    optionData(newVal) {
      this.chartData = newVal;
      this.init();
    },
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      let myChart = echarts.init(this.$refs[this.refName]);
      let option = {
        graphic: [
          {
            type: "text",
            left: "5%",
            top: "5%",
            style: {
              text: "网点健康度PK",
              fontSize: 20,
            },
          },
        ],
        color: ["#F4B259", "#2087D0"],
        legend: { right: "5%", top: "5%" },
        tooltip: {},
        grid: {
          left: "5%",
          bottom: "10%",
          right: "5%",
          top: "15%",
        },
        dataset: {
          source: [
            ["product", "辽宁盘锦公司82.6分", "辽宁大连金州区凤翔93.8分"],
            ["业务量", 89, 160],
            ["进港投诉率", 125, 125],
            ["频次签收率", 30, 70],
            ["遗失率", 120, 160],
            ["破损率", 120, 160],
            ["伪签率", 30, 80],
            ["工单及时解决率", 30, 80],
            ["交货滞留率", 30, 80],
            ["行政处罚", 30, 80],
          ],
        },
        xAxis: {
          type: "category",
          axisLabel: {
            interval: 0
          },
          axisTick: {
            show: false
          },
        },
        yAxis: {
          type: "value",
          splitLine: {
            show: false,
          },
          axisLabel: {
            show: true,
          },
          axisLine: {
            show: true,
          },
          axisTick: { show: true },
        },
        series: [
          {
            type: "bar",
            itemStyle: {
              borderRadius: [10, 10, 10, 10],
            },
          },
          {
            type: "bar",
            itemStyle: {
              borderRadius: [10, 10, 10, 10],
            },
          },
        ],
        barWidth: 20,
      };

      option && myChart.setOption(option);
    },
  },
};
</script>
